local ClientOHOH = _G.ClientOHOH;

local M = ClientOHOH.class.new(script, ClientOHOH.files.BaseObject())
local CallBackManager = ClientOHOH.load.CallBackManager();

local instStr={
    buyPack="ctrl.topNav.buyPack", --购买背包
    buyEquip ="ctrl.topNav.buyPet",--购买装备数量
    infoPack="ctrl.topNav.num_buyPack", --购买背包
    infoEquip ="ctrl.topNav.num_buyPet",--购买装备数量

    ShowLockBtn ="ctrl.Lock.btn_lock",--进入锁定状态
    ShowSellBtn ="ctrl.Delete.btn_del",--进入删除状态
}


function M.new(...)
	return M(...);
end;


function M.ctor(self,ctrl)
    M.super.ctor(self);

    self.ctrl=ctrl
    self.ui=ctrl:InitUiInst2(ctrl.main_inst,instStr)

    self.EquipCount=0
    self.HadCount=0
    self.NowSlots=0
    self.MaxSlots=0
    self.NowPack=0
    self.MaxPack=0

    self.ctrl.StatusChangeEvent:Connect(function(id)
        if id=="equip" then
            self.ui.ShowLockBtn.Visible=true
            self.ui.ShowSellBtn.Visible=true
        else
            self.ui.ShowLockBtn.Visible=false
            self.ui.ShowSellBtn.Visible=false
        end
    end)


    CallBackManager:AddRbxConnect(self,self.ui.buyPack.Activated, function()
        self.ctrl.BuyPackEvent:Action()
	end);

    CallBackManager:AddRbxConnect(self,self.ui.buyEquip.Activated, function()
        self.ctrl.BuyEquipEvent:Action()
	end);

    --------------------------------------------------------------------------------------
    CallBackManager:AddRbxConnect(self,self.ui.ShowLockBtn.Activated, function()
        self.ctrl:ShowOnlyStatu("lock")

	end);

    CallBackManager:AddRbxConnect(self,self.ui.ShowSellBtn.Activated, function()
        self.ctrl:ShowOnlyStatu("sell")
	end);


end;


function M.dtor(self)
	M.super.dtor(self);
end;

function M.UpdateSlotsEquip(self,now,max)
    self.NowSlots=now
    self.MaxSlots=max
    self:Update()
end

function M.UpdatePetPack(self,now,max)
    self.NowPack=now
    self.MaxPack=max
    self:Update()
end
function M.UpdateEquip(self,equip)
    local count=0
    for k,v in pairs(equip) do
        count=count+v
    end
    self.EquipCount=count
    self:Update()
end

function M.UpdateHad(self,had)
    local count=0
    for k,v in pairs(had) do
        count=count+v
    end
    self.HadCount=count
    self:Update()
end
function M.Update(self)
    
    if self.NowSlots==self.MaxSlots then
        self.ui.buyEquip.Visible=false
    else
        self.ui.buyEquip.Visible=true
    end

    if self.NowPack==self.MaxPack then

        self.ui.buyPack.Visible=false
    else
        self.ui.buyPack.Visible=true
    end

    self.ui.infoPack.Text=self.HadCount.."/"..self.NowPack
    self.ui.infoEquip.Text=self.EquipCount.."/"..self.NowSlots
end


return M